package com.spagettikod.t437.simpledb;

import javax.swing.JTable;

import com.spagettikod.t437.T437;
import com.xerox.amazonws.sdb.Domain;

public class SimpleDBJTable extends JTable
{
	private static final long serialVersionUID = 2741534052269090471L;

	public SimpleDBJTable()
	{
		super();
		setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS);
	}

	public void setDomain(Domain domain)
	{
		setModel(new SimpleDBTableModel(domain));
	}

	private int getVisibleRows()
	{
		Float rows = new Float(T437.getApplicationFrame().getSize().height) / new Float(getRowHeight());
		return Math.round(rows.floatValue());
	}

	public void queryData(String queryString)
	{
		if (getModel() instanceof SimpleDBTableModel)
		{
			((SimpleDBTableModel) getModel()).queryData(queryString, getVisibleRows());
		}
	}

	public void fetchData(String queryString, boolean forceFetch)
	{
		if (getModel() instanceof SimpleDBTableModel)
		{
			((SimpleDBTableModel) getModel()).fetchData(queryString, getVisibleRows(), forceFetch);
		}
	}
}
